package com.site.wisdom_construction.controller.publicModule;

import com.alibaba.fastjson.JSONObject;
import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.publicModule.BadnessLabourTypeService;
import com.site.wisdom_construction.service.publicModule.HonorLabourTypeService;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2021/12/29
 * @Description
 */
@Api(tags = "劳务队荣誉行为类型接口")
@RestController
@RequestMapping("HonorLabourType")
@CrossOrigin
public class HonorLabourTypeController {
    @Autowired
    private HonorLabourTypeService honorLabourTypeService;

    @ApiOperation(value = "增加劳务队荣誉行为类型信息", notes = "测试数据:")
    @PostMapping("/insertHonorLabourType")
    public JsonResult insertProfession(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = honorLabourTypeService.insertHonorLabourType(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入劳务队荣誉行为类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入劳务队荣誉行为类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除劳务队荣誉行为类型信息", notes = "测试数据:")
    @PostMapping("/deleteHonorLabourType")
    public JsonResult deleteProfession(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = honorLabourTypeService.deleteHonorLabourType(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除劳务队荣誉行为类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除劳务队荣誉行为类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改劳务队荣誉行为类型信息", notes = "测试数据:")
    @PostMapping("/updateHonorLabourType")
    public JsonResult updateProfession(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = honorLabourTypeService.updateHonorLabourType(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改劳务队荣誉行为类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改劳务队荣誉行为类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询劳务队荣誉行为类型信息", notes = "测试数据:")
    @PostMapping("/findHonorLabourTypeByPage")
    public Page findProfessionByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(honorLabourTypeService.Total(map));
        page.setItems(honorLabourTypeService.findHonorLabourTypeByPage(map));
        return page;
    }

    @ApiOperation(value = "下拉框查询劳务队荣誉行为类型信息", notes = "测试数据:")
    @PostMapping("/selectHonorLabourType")
    public OneDataResult selectHonorLabourType(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(honorLabourTypeService.selectHonorLabourType());
        return oneDataResult;
    }


    @ApiOperation(value = "批量导入劳务队荣誉行为类型信息", notes = "测试数据:")
    @PostMapping("/batchInsertHonorLabourType")
    public void batchInsertHonorLabourType(@RequestBody Map map) {
        List list = (List) map.get("data");
        for (int i = 0; i < list.size(); i++) {
            Map mapR = new HashMap();
            JSONObject json = (JSONObject) JSONObject.toJSON(list.get(i));
            mapR.put("typeName", json.get("name"));
            honorLabourTypeService.insertHonorLabourType(mapR);
        }
    }
}
